<template>
  <div>
    <div class="returnTitle">
      <el-page-header @back="goBack" content="危机管理"></el-page-header>
    </div>
    <div class="center">
      <el-form ref="form" :model="form" label-position="top">
        <el-form-item label="危机人员：">
          <el-col :span="12" :xl="{span: 24}">
            {{this.name}}
          </el-col>
        </el-form-item>
        <h3>危机情况：</h3>
        <el-form-item label="危机类型：">
          <el-col :span="12" :xl="{span: 24}">
            <el-select v-model="form.type" placeholder="请选择危机类型">
              <el-option v-for="item in this.optionsList.crisis_list" :key="item.id" :label="item.title" :value="item.id"></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="是否已经发生事件？">
          <el-radio-group v-model="form.whether_happen" @change="againFn()">
            <el-radio label="1">没有发生</el-radio>
            <el-radio label="2">正在发生</el-radio>
            <el-radio label="3">已经发生</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="this.form.whether_happen === '3'" label="到目前为止，危机事件已经发生多长时间？">
          <el-radio-group v-model="form.crisis_duration">
            <el-radio label="1">一周内</el-radio>
            <el-radio label="2">超过一周</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="this.form.whether_happen === '2'" label="当事人是否失踪或死亡？">
          <el-radio-group v-model="form.missing_death">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="this.form.missing_death !== '' && this.form.crisis_duration === ''" label="发生地点？">
          <el-radio-group v-model="form.happen_place">
            <el-radio label="1">校内</el-radio>
            <el-radio label="2">校外</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="this.form.whether_happen !== '' && this.form.missing_death !== '1'" label="当事人是否需要休学或休假？">
          <el-radio-group v-model="form.suspension_school">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="this.form.whether_happen && this.form.whether_happen !== '1'" label="危机事件影响范围：">
          <el-col :span="12" :xl="{span: 24}">
            <el-select v-model="form.influence_range" placeholder="请选择危机事件影响范围">
              <el-option v-for="item in this.optionsList.influence_scope_list" :key="item.id" :label="item.title" :value="item.id"></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item v-if="this.form.whether_happen && this.form.whether_happen !== '1'" label="危机事情现场情况">
          <el-radio-group v-model="form.influence_degree">
            <el-radio label="1">现场有涉事人</el-radio>
            <el-radio label="2">现场没有涉事人</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="评估人：">
          <el-tag v-for="tag in personnelList" :key="tag.uid" closable @close="removeTag(tag)"> {{tag.full_name}} </el-tag>
          <el-button type="text" @click="selectPersonnelFn()">选择其他人员</el-button>
        </el-form-item>
        <el-form-item label="危机评估说明：">
          <el-input type="textarea" :rows="2" v-model="form.assessment_notes"></el-input>
        </el-form-item>
        <el-form-item class="inputBox">
          <el-button type="primary" @click="submitFn()">保 存</el-button>
        </el-form-item>
      </el-form>
    </div>
    <add-personnel v-if="this.isAddPersonnel" :isAddPersonnel="isAddPersonnel" @noAddPersonnel="noAddPersonnel"></add-personnel>
  </div>
</template>
<script>
import addPersonnel from './addPersonnel.vue'
import {APICRISISGETSUNDRY, APICRISISMODIFYSUPPLEMENTINFORMATION} from '@/common/api.js'
export default {
  props: [],
  components: {addPersonnel},
  data () {
    return {
      name: '',
      optionsList: {},
      form: {
        type: '',
        whether_happen: '',
        crisis_duration: '',
        missing_death: '',
        happen_place: '',
        suspension_school: '',
        influence_range: '',
        influence_degree: '',
        assessor: '',
        assessment_notes: ''
      },
      isAddPersonnel: false,
      personnelList: []
    }
  },
  created () {
    this.form.uid = this.$route.query.uid
    this.form.id = this.$route.query.id
    this.name = this.$route.query.name
    this.selectFn()
  },
  methods: {
    goBack () {
      this.$router.push({path: '/crisis'})
    },
    selectFn () {
      APICRISISGETSUNDRY().then((res) => {
        this.optionsList = res.data
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    againFn () {
      this.form.crisis_duration = ''
      this.form.missing_death = ''
      this.form.happen_place = ''
      this.form.suspension_school = ''
    },
    selectPersonnelFn () {
      this.isAddPersonnel = true
    },
    noAddPersonnel (type) {
      this.personnelList = type !== [] ? type : []
      this.isAddPersonnel = false
    },
    removeTag (tag) {
      this.personnelList.splice(this.personnelList.indexOf(tag), 1)
    },
    submitFn () {
      var arr = []
      this.personnelList.forEach(item => {
        arr.push(item.uid)
      })
      this.form.assessor = arr.toString()
      APICRISISMODIFYSUPPLEMENTINFORMATION(this.form).then((res) => {
        this.$message.success(res.msg)
        this.$router.push({path: './crisis'})
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>
<style>
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
  .el-form-item__label{
    font-weight: bold;
  }
</style>
